home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '90 / MacHack'90 Proceedings / John Norstad / Reusable Code / Source / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-10  |  20.7 KB  |  797 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________________________
  2.  
  3.     misc.c - Miscellany Module
  4.     
  5.     Copyright © 1988, 1989, 1990 Northwestern University.  Permission is 
  6.     granted to use this code in your own projects, provided you give credit 
  7.     to both John Norstad and Northwestern University in your about box or 
  8.     document.
  9.     
  10.     This module takes care of various miscellaneous tasks.
  11. _____________________________________________________________________*/
  12.  
  13.  
  14. #pragma load "precompile"
  15. #include "utl.h"
  16. #include "scn.h"
  17. #include "vol.h"
  18. #include "rep.h"
  19. #include "rez.h"
  20. #include "glob.h"
  21. #include "vmsg.h"
  22. #include "wstm.h"
  23. #include "unmount.h"
  24. #include "misc.h"
  25. #include "prog.h"
  26. #include "main.h"
  27. #include "vscn.h"
  28.  
  29. #pragma segment misc
  30.  
  31. /*______________________________________________________________________
  32.  
  33.     misc_HiliteScan - Hilite Scan and Disinfect Buttons.
  34.     
  35.     Exit:    Scan and Disinfect buttons hilited iff there is a current
  36.             volume.
  37. _____________________________________________________________________*/
  38.  
  39.  
  40. void misc_HiliteScan(void)
  41.  
  42. {
  43.     short            vRefNum;                /* ref num of selected vol */
  44.     short            hiliteVal;            /* 0 to hilite, 255 to unhilite */
  45.     
  46.     main_SetPort();
  47.     hiliteVal = (vol_GetSel(&vRefNum) == nsvErr) ? 255 : 0;
  48.     HiliteControl(Controls[scanID-firstControl], hiliteVal);
  49.     HiliteControl(Controls[disinfectID-firstControl], 
  50.         DisableDisinfect ? 255 : hiliteVal);
  51. }
  52.  
  53. /*______________________________________________________________________
  54.  
  55.     misc_ClearReport - Clear the Report.
  56. _____________________________________________________________________*/
  57.  
  58.  
  59. void misc_ClearReport (void)
  60.  
  61. {
  62.     Rect                inval;            /* rect to be invalidated */
  63.  
  64.     rep_Clear(Report);
  65.     rep_Fill(Report, repHeadID, false);
  66.     rep_GetRect(Report, &inval);
  67.     InsetRect(&inval, 1, 1);
  68.     InvalRect(&inval);
  69.     RepInfected = false;
  70.     vmsg_ClearTags();
  71. };
  72.  
  73. /*______________________________________________________________________
  74.  
  75.     LoadAll - Load all Disinfectant Resources of a Given Type
  76.     
  77.     Entry:        rType = resource type.
  78. _____________________________________________________________________*/
  79.  
  80.  
  81. static void LoadAll (OSType rType)
  82.  
  83. {
  84.     short                i;                /* loop index */
  85.     short                n;                /* number of resources of type */
  86.     Handle            h;                /* handle to resource */
  87.     
  88.     n = CountResources(rType);
  89.     SetResLoad(false);
  90.     for (i = 1; i <= n; i++) {
  91.         h = GetIndResource(rType, i);
  92.         if (!*h && HomeResFile(h) == DfectRefNum) LoadResource(h);
  93.     };
  94.     SetResLoad(true);
  95. }
  96.  
  97. /*______________________________________________________________________
  98.  
  99.     misc_CheckEject - Check for Eject of System or Disinfectant Volume
  100.     
  101.     Entry:        refNum = vol ref num or drive num of volume about
  102.                         to be ejected.
  103.                         
  104.     If the system volume or Disinfectant's volume is about to be ejected, 
  105.     this routine loads all the resources which might be needed from the system 
  106.     file or from the Disinfectant file.
  107. _____________________________________________________________________*/
  108.  
  109.  
  110. void misc_CheckEject (short refNum)
  111.  
  112. {
  113.     Handle                h;                /* handle to resource */
  114.     short                    vRefNum;        /* vol ref num */
  115.     Str255                volName;        /* vol name */
  116.     long                    freeBytes;    /* free bytes on vol */
  117.     Handle                hdlog;        /* handle to please wait dialog template */
  118.     DialogPtr            dlog;            /* pointer to please wait dialog */
  119.     static Boolean        firstTime=true;    /* true if haven't preloaded
  120.                                                         resources yet */
  121.  
  122.     /* Convert a drive number to a vol ref number. */
  123.     
  124.     if (refNum > 0) {
  125.         (void) GetVInfo(refNum, volName, &vRefNum, &freeBytes);
  126.     } else {
  127.         vRefNum = refNum;
  128.     };
  129.  
  130.     /* Put up "Please wait" dialog if we need to load resources for 
  131.         the first time. */
  132.  
  133.     dlog = nil;
  134.     if (vRefNum == SysVol || vRefNum == DfectVol) {
  135.         if (firstTime) {
  136.             SetCursor(*Watch);
  137.             hdlog = GetResource('DLOG', plsWaitID);
  138.             HNoPurge(hdlog);
  139.             utl_CenterDlogRect(*(Rect**)hdlog, false);
  140.             dlog = GetNewDialog(plsWaitID, nil, (WindowPtr)-1);
  141.             ShowWindow((WindowPtr)dlog);
  142.             DrawDialog(dlog);
  143.         };
  144.         firstTime = false;
  145.     } else {
  146.         return;
  147.     };
  148.         
  149.     /* If ejecting Disinfectant volume, load Disinfectant resources that 
  150.         we might need later. */
  151.     
  152.     if (vRefNum == DfectVol) {
  153.         SetCursor(*Watch);
  154.         LoadAll('PICT');
  155.         LoadAll('WIND');
  156.         LoadAll('CNTL');
  157.         LoadAll('ALRT');
  158.         LoadAll('DITL');
  159.         LoadAll('DLOG');
  160.         LoadAll('STR#');
  161.         LoadAll('SICN');
  162.         LoadAll('CURS');
  163.         LoadAll('TCON');
  164.         LoadAll('TAG ');
  165.         LoadAll('CELL');
  166.         LoadAll('LDEF');
  167.         LoadAll('CODE');
  168.         LoadAll('CREA');
  169.     };
  170.     
  171.     /* If ejecting System volume, load system resources that we
  172.         might need later. */
  173.  
  174.     if (vRefNum == SysVol) {
  175.         SetCursor(*Watch);
  176.         (void) utl_CheckPack(listMgr, true);
  177.         (void) utl_CheckPack(stdFile, true);
  178.         (void) utl_CheckPack(dskInit, true);
  179.         (void) utl_CheckPack(intUtil, true);
  180.         (void) utl_CheckPack(bdConv, true);
  181.         CouldDialog(putDlgID);
  182.         CouldAlert(sfNoPrivs);
  183.         CouldAlert(sfBadChar);
  184.         CouldAlert(sfSysErr);
  185.         CouldAlert(sfReplaceExisting);
  186.         CouldAlert(sfDiskLocked);
  187.         utl_DILoad();
  188.         h = GetResource('MBDF', 0);
  189.         h = GetResource('MDEF', 0);
  190.         h = GetResource('itl0', 0);
  191.         h = GetResource('ICON', stopIcon);
  192.         h = GetResource('ICON', noteIcon);
  193.         /* call SysBeep to force snd and snth resources to be loaded. */
  194.         SysBeep(beepDuration);
  195.     };
  196.     
  197.     /* Dispose of please wait dialog. */
  198.     
  199.     if (dlog) {
  200.         DisposDialog(dlog);
  201.         HPurge(hdlog);
  202.     };
  203.     
  204.     misc_SetCursor();
  205. }
  206.     
  207. /*______________________________________________________________________
  208.  
  209.     misc_SetCursor - Set Cursor.
  210. _____________________________________________________________________*/
  211.  
  212.  
  213. void misc_SetCursor (void)
  214.  
  215. {
  216.     if (!InForeground) return;
  217.     if (HelpMode) {
  218.         SetCursor(*HelpCurs);
  219.         misc_DisableBB();
  220.     } else if (!Scanning || misc_GetWindKind(FrontWindow()) != mainWind) {
  221.         InitCursor();
  222.         misc_DisableBB();
  223.     } else if (FloppyWait) {
  224.         SetCursor(*FloppyCurs);
  225.         misc_DisableBB();
  226.     } else if (Scanning) {
  227.         utl_InitSpinCursor(BBCursors, numBalls, spinInterval);
  228.         misc_EnableBB();
  229.     };
  230. }
  231.  
  232. /*______________________________________________________________________
  233.  
  234.     misc_ValPrint - Validate Print Record.
  235.     
  236.     Entry:    p = pointer to rpp param block.
  237.                 p->hPrint = pointer to print record, or nil if none
  238.                     yet allocated.
  239.                 report = true if this is for a report printing operation.
  240.                 report = false if this is for a document printing operation.
  241.     
  242.     Exit:        p->hPrint = pointer to print record.  A new one is allocated
  243.                     if necessary, and any existing one is validated.
  244.                     
  245.                 If a new print record is allocated, or if the existing one
  246.                 was invalid, then the other fields in the rpp param block
  247.                 are also initialized.  The initial values depend on whether
  248.                 this is a report or document being printed, and whether
  249.                 the output device is a LaserWriter or ImageWriter.
  250. _____________________________________________________________________*/
  251.  
  252.  
  253. void misc_ValPrint (rpp_PrtBlock *p, Boolean report)
  254.  
  255. {
  256.     Boolean                laser;            /* true if laserwriter */
  257.     char                    *defFont1;        /* pointer to first default font name */
  258.     char                    *defFont2;        /* pointer to second default font name */
  259.     short                    defSize1;        /* first default size */
  260.     short                    defSize2;        /* second default size */
  261.  
  262.     if (p->hPrint) {
  263.         if (!PrValidate(p->hPrint)) return;
  264.     } else {
  265.         p->hPrint = (THPrint)NewHandle(sizeof(TPrint));
  266.         PrintDefault(p->hPrint);
  267.         defSize1 = (**(p->hPrint)).prInfo.iVRes;
  268.     };
  269.     laser = utl_IsLaser(p->hPrint);
  270.     if (report) {
  271.         if (laser) {
  272.             defFont1 = defFont2 = "\pHelvetica";
  273.         } else {
  274.             defFont1 = defFont2 = "\pGeneva";
  275.         };
  276.         defSize1 = defSize2 = 10;
  277.         p->topMargin = p->botMargin = 75;
  278.         p->leftMargin = p->rightMargin = 150;
  279.     } else {
  280.         if (laser) {
  281.             defFont1 = "\pPalatino";
  282.             defSize1 = 10;
  283.             defFont2 = "\pTimes";
  284.             defSize2 = 12;
  285.         } else {
  286.             defFont1 = defFont2 = "\pGeneva";
  287.             defSize1 = defSize2 = 10;
  288.         };
  289.         p->topMargin = p->botMargin = 50;
  290.         p->leftMargin = p->rightMargin = 100;
  291.     };
  292.     p->reverseOrder = laser ? true : false;
  293.     if (utl_GetFontNumber(defFont1, &p->fontNum)) {
  294.         p->fontSize = defSize1;
  295.     } else if (utl_GetFontNumber(defFont2, &p->fontNum)) {
  296.         p->fontSize = defSize2;
  297.     } else {
  298.         p->fontNum = applFont;
  299.         p->fontSize = defSize1;
  300.     };
  301.     p->header = true;
  302.     p->titleSep = report ? 25 : 40;
  303.     p->titleFont = p->fontNum;
  304.     p->titleStyle = bold;
  305.     p->titleSize = utl_ScaleFontSize(p->fontNum, p->fontSize, 90, laser);
  306.     p->dlogID = prDlogID;
  307.     p->tabConID = tconID;
  308.     p->emptyPageRangeID = noPagesID;
  309.     p->ditlID = pageSetupID;
  310.     p->sizeRangeID = illegalSizeID;
  311.     p->marginsTooBigID = marTooBigID;
  312.     p->minFontSize = 1;
  313.     p->maxFontSize = 24;
  314.     p->updateAll = misc_Update;
  315. }
  316.  
  317. /*______________________________________________________________________
  318.  
  319.     misc_ReadPref - Read the Preferences File.
  320. _____________________________________________________________________*/
  321.  
  322.  
  323. #pragma segment init
  324.  
  325. void misc_ReadPref (void)
  326.  
  327. {
  328.     ParamBlockRec        pBlockMFS;        /* param block for PBSetVol call */
  329.     WDPBRec                pBlockHFS;        /* param block for PBHSetVol call */
  330.     Str255                fName;            /* "Disinfectant Prefs" file name */
  331.     OSErr                    rCode;            /* result code */
  332.     short                    refNum;            /* resource file refnum */
  333.     Boolean                error;            /* true if error encountered */
  334.     char                    version[30];    /* version number */
  335.     Handle                thePrefs;        /* handle to prefs resource */
  336.     
  337.     /* Set the default volume and directory to the system volume and the
  338.         blessed folder. */
  339.     
  340.     if (utl_VolIsMFS(SysVol)) {
  341.         pBlockMFS.volumeParam.ioNamePtr = nil;
  342.         pBlockMFS.volumeParam.ioVRefNum = SysVol;
  343.         rCode = PBSetVol(&pBlockMFS, false);
  344.     } else {
  345.         pBlockHFS.ioNamePtr = nil;
  346.         pBlockHFS.ioVRefNum = SysVol;
  347.         pBlockHFS.ioWDDirID = SysDirID;
  348.         rCode = PBHSetVol((WDPBPtr)&pBlockHFS, false);
  349.     };
  350.     error = rCode;
  351.     
  352.     /* Open the "Disinfectant Prefs" resource file with read-only permission. */
  353.     
  354.     refNum = -1;
  355.     if (!error) {
  356.         GetIndString(fName, strListID, prefsFileName);
  357.         if (OldRom) {
  358.             refNum = OpenResFile(fName);
  359.         } else {
  360.             refNum = OpenRFPerm(fName, 0, fsRdPerm);
  361.         };
  362.         error = refNum == -1;
  363.     };
  364.     
  365.     /* Load the prefs resource. */
  366.     
  367.     if (!error) {
  368.         thePrefs = GetResource('DPRF', 0);
  369.         error = !thePrefs;
  370.     };
  371.     
  372.     /* Check for the proper size of the resource. */
  373.     
  374.     if (!error) error = GetHandleSize(thePrefs) != sizeof(Prefs);
  375.     
  376.     /* Copy the contents of the prefs resource to the global Prefs variable. */
  377.     
  378.     if (!error) memcpy(&Prefs, *thePrefs, sizeof(Prefs));
  379.     
  380.     /* Check the version number. */
  381.     
  382.     if (!error) {
  383.         GetIndString(version, strListID, versionStr);
  384.         error = !EqualString(version, Prefs.version, false, false);
  385.     };
  386.     
  387.     /* Copy the print records into relocatable blocks, and store handles
  388.         to them in the print blocks. */
  389.         
  390.     if (!error && Prefs.mainPrint.hPrint)
  391.         error = PtrToHand((Ptr)&Prefs.mainPrintRec, 
  392.             (Handle*)&Prefs.mainPrint.hPrint,
  393.             sizeof(TPrint));
  394.     if (!error && Prefs.helpPrint.hPrint)
  395.         error = PtrToHand((Ptr)&Prefs.helpPrintRec, 
  396.             (Handle*)&Prefs.helpPrint.hPrint,
  397.             sizeof(TPrint));
  398.     
  399.     /* If any error was encountered, initialize the Prefs global variable to
  400.         default values. */
  401.         
  402.     if (error) {
  403.         GetIndString(Prefs.version, strListID, versionStr);
  404.         wstm_Init(&Prefs.mainState);
  405.         wstm_Init(&Prefs.helpState);
  406.         wstm_Init(&Prefs.prefState);
  407.         wstm_Init(&Prefs.abouState);
  408.         Prefs.mainPrint.hPrint = nil;
  409.         Prefs.helpPrint.hPrint = nil;
  410.         Prefs.numOpenWind = 1;
  411.         Prefs.openWind[0] = mainWind;
  412.         Prefs.helpScrollPos = 0;
  413.         Prefs.beepCount = 0;
  414.         Prefs.scanningStation = false;
  415.         Prefs.scanningStationOp = checkOp;
  416.         Prefs.repCreator = 'ttxt';
  417.         Prefs.docCreator = 'MSWD';
  418.         Prefs.repOtherCre = '????';
  419.         Prefs.docOtherCre = '????';
  420.         Prefs.notifOption = notifIcon;
  421.     };
  422.     
  423.     /* Close the resource file. */
  424.     
  425.     if (refNum != -1) CloseResFile(refNum);
  426. }
  427.  
  428. #pragma segment misc
  429.  
  430. /*______________________________________________________________________
  431.  
  432.     misc_WritePref - Write the Preferences File.
  433. _____________________________________________________________________*/
  434.  
  435.  
  436. void misc_WritePref (void)
  437.  
  438. {
  439.     ParamBlockRec        pBlockMFS;        /* param block for PBSetVol call */
  440.     WDPBRec                pBlockHFS;        /* param block for PBHSetVol call */
  441.     Str255                fName;            /* "Disinfectant Prefs" file name */
  442.     OSErr                    rCode;            /* result code */
  443.     short                    refNum;            /* resource file refnum */
  444.     Boolean                error;            /* true if error encountered */
  445.     FInfo                    fndrInfo;        /* Finder info */
  446.     Handle                thePrefs;        /* handle to prefs resource */
  447.     short                    numOpenWind;    /* number of open windows */
  448.     WindowPtr            curWind;            /* ptr to cur window */
  449.     WindowObject        *curObj;            /* ptr to cur window object */
  450.     WindowPtr            nextWind;        /* ptr to next window */
  451.     WindKind                windKind;        /* window kind */
  452.     
  453.     /* Walk the window list.  Close all windows, and save the open window
  454.         states and orders in the Prefs variable. */
  455.         
  456.     numOpenWind = 0;
  457.     curWind = FrontWindow();
  458.     while (curWind) {
  459.         nextWind = (WindowPtr)((WindowPeek)curWind)->nextWindow;
  460.         windKind = misc_GetWindKind(curWind);
  461.         if (windKind != daWind) {
  462.             Prefs.openWind[numOpenWind] = windKind;
  463.             numOpenWind++;
  464.             curObj = (WindowObject*)((WindowPeek)curWind)->refCon;
  465.             (*curObj->close)();
  466.         };
  467.         curWind = nextWind;
  468.     };
  469.     Prefs.numOpenWind = numOpenWind;
  470.     
  471.     /* Copy the print records into the Prefs variable. */
  472.     
  473.     if (Prefs.mainPrint.hPrint) 
  474.         memcpy(&Prefs.mainPrintRec, *Prefs.mainPrint.hPrint, sizeof(TPrint));
  475.     if (Prefs.helpPrint.hPrint)
  476.         memcpy(&Prefs.helpPrintRec, *Prefs.helpPrint.hPrint, sizeof(TPrint));
  477.     
  478.     /* Set the default volume and directory to the system volume and the
  479.         blessed folder. */
  480.     
  481.     if (utl_VolIsMFS(SysVol)) {
  482.         pBlockMFS.volumeParam.ioNamePtr = nil;
  483.         pBlockMFS.volumeParam.ioVRefNum = SysVol;
  484.         rCode = PBSetVol(&pBlockMFS, false);
  485.     } else {
  486.         pBlockHFS.ioNamePtr = nil;
  487.         pBlockHFS.ioVRefNum = SysVol;
  488.         pBlockHFS.ioWDDirID = SysDirID;
  489.         rCode = PBHSetVol((WDPBPtr)&pBlockHFS, false);
  490.     };
  491.     error = rCode;
  492.     
  493.     /* Open the "Sample Prefs" resource file with read/write permission.
  494.         If it doesn't exist, create it with type SMP1 and creator SAMP. */
  495.     
  496.     refNum = -1;
  497.     if (!error) {
  498.         GetIndString(fName, strListID, prefsFileName);
  499.         if (OldRom) {
  500.             refNum = OpenResFile(fName);
  501.         } else {
  502.             refNum = OpenRFPerm(fName, 0, fsRdWrPerm);
  503.         };
  504.         if (refNum == -1) {
  505.             CreateResFile(fName);
  506.             if (!(error = ResError())) {
  507.                 if (!(error = GetFInfo(fName, 0, &fndrInfo))) {
  508.                     fndrInfo.fdType = 'D2C1';
  509.                     fndrInfo.fdCreator = 'D2CT';
  510.                     if (!(error = SetFInfo(fName, 0, &fndrInfo))) {
  511.                         if (OldRom) {
  512.                             refNum = OpenResFile(fName);
  513.                         } else {
  514.                             refNum = OpenRFPerm(fName, 0, fsRdWrPerm);
  515.                         };
  516.                         error = refNum == -1;
  517.                     };
  518.                 };
  519.             };
  520.         };
  521.     };
  522.     
  523.     /* Load the prefs resource.  If no such resource exists, create one. */
  524.     
  525.     if (!error) {
  526.         thePrefs = GetResource('DPRF', 0);
  527.         if (!thePrefs) {
  528.             thePrefs = NewHandle(sizeof(Prefs));
  529.             AddResource(thePrefs, 'DPRF', 0, "\p");
  530.             error = ResError();
  531.         };
  532.     };
  533.     
  534.     /* Set the proper size of the resource and copy the Prefs global variable
  535.         to the resource. */
  536.     
  537.     if (!error) error = PtrToXHand((Ptr)&Prefs, thePrefs, sizeof(Prefs));
  538.     
  539.     /* Mark the resource changed. */
  540.     
  541.     if (!error) ChangedResource(thePrefs);
  542.     
  543.     /* Close the resource file. */
  544.     
  545.     if (refNum != -1) CloseResFile(refNum);
  546. }
  547.  
  548. /*______________________________________________________________________
  549.  
  550.     misc_GetWindKind - Get Window Kind.
  551.     
  552.     Entry:    theWindow = pointer to window.
  553.     
  554.     Exit:        function result = window kind.
  555. _____________________________________________________________________*/
  556.  
  557.  
  558. WindKind misc_GetWindKind (WindowPtr theWindow)
  559.  
  560. {
  561.     return utl_IsDAWindow(theWindow) ?
  562.         daWind :
  563.         ((WindowObject*)((WindowPeek)theWindow)->refCon)->windKind;
  564. }
  565.  
  566. /*______________________________________________________________________
  567.  
  568.     misc_Notify - Notify User.
  569.     
  570.     Entry:    msg = index in STR# resource of message.
  571.                 wait = true to wait until brought to foreground.
  572. _____________________________________________________________________*/
  573.  
  574.  
  575. void misc_Notify (short msg, Boolean wait)
  576.  
  577. {
  578.     if (InForeground) return;
  579.     if (utl_SysHasNotMgr && !Notified) {
  580.         Notified = true;
  581.         NotifRec.qType = nmType;
  582.         NotifRec.nmMark = 1;
  583.         NotifRec.nmSIcon = Prefs.notifOption == notifDiamond ? nil : 
  584.             GetResource('SICN', smallDfectIconID);
  585.         if (Prefs.notifOption == notifAlert) {
  586.             NotifRec.nmSound = (Handle)-1;
  587.             NotifRec.nmStr = NotifString;
  588.             GetIndString(NotifString, strListID, msg);
  589.             NotifRec.nmResp = (ProcPtr)-1;
  590.         } else {
  591.             NotifRec.nmSound = nil;
  592.             NotifRec.nmStr = nil;
  593.             NotifRec.nmResp = nil;
  594.         };
  595.         NMInstall((QElemPtr)&NotifRec);
  596.     };
  597.     if (!wait) return;
  598.     while (!InForeground) prog_Event();
  599. }
  600.  
  601. /*______________________________________________________________________
  602.  
  603.     misc_Update - Process All Pending Update Events.
  604. _____________________________________________________________________*/
  605.  
  606.  
  607. void misc_Update (void)
  608.  
  609. {
  610.     EventRecord            event;
  611.  
  612.     while (EventAvail(updateMask, &event)) prog_Event();
  613. }
  614.  
  615. /*______________________________________________________________________
  616.  
  617.     CopyINITResource - Copy Disinfectant INIT Resource.
  618.     
  619.     Entry:        oldType = old resource type.
  620.                     oldID = old resource id.
  621.                     newType = new resource type.
  622.                     newID = new resource id.
  623.                     newAttr = new resource attributes.
  624. _____________________________________________________________________*/
  625.  
  626.  
  627. static OSErr CopyINITResource (OSType oldType, short oldID,
  628.     OSType newType, short newID, short newAttr)
  629.     
  630. {
  631.     Handle            h;                /* handle to resource */
  632.     OSErr                rCode;        /* result code */
  633.     
  634.     h = GetResource(oldType, oldID);
  635.     if (!h) return resNotFound;
  636.     DetachResource(h);
  637.     if (rCode = ResError()) return rCode;
  638.     AddResource(h, newType, newID, "\p");
  639.     if (rCode = ResError()) return rCode;
  640.     SetResAttrs(h, GetResAttrs(h) | newAttr);
  641.     return rCode;
  642. }
  643.  
  644. /*______________________________________________________________________
  645.  
  646.     misc_InstallINIT - Install Disinfectant INIT.
  647. _____________________________________________________________________*/
  648.  
  649.  
  650. void misc_InstallINIT (void)
  651.  
  652. {
  653. }
  654.  
  655. /*______________________________________________________________________
  656.  
  657.     misc_ExtractINIT - Extract Disinfectant INIT.
  658. _____________________________________________________________________*/
  659.  
  660.  
  661. void misc_ExtractINIT (void)
  662.  
  663. {
  664. }
  665.  
  666. /*______________________________________________________________________
  667.  
  668.     misc_PrintError - Handle Printing Error.
  669. _____________________________________________________________________*/
  670.  
  671.  
  672. void misc_PrintError (OSErr rCode)
  673.  
  674. {
  675.     Str255            rCodeStr;    /* result code as a string */
  676.     
  677.     if (rCode && rCode != iPrAbort) {
  678.         if (rCode == fnfErr) {
  679.             utl_StopAlert(noDriverID, nil, 0);
  680.         } else if (rCode == resNotFound) {
  681.             utl_StopAlert(noPrinterID, nil, 0);
  682.         } else  if (rCode == dskFulErr) {
  683.             utl_StopAlert(printDskFullID, nil, 0);
  684.         } else if (rCode == wPrErr) {
  685.             utl_StopAlert(printLockedID, nil, 0);
  686.         } else {
  687.             NumToString(rCode, rCodeStr);
  688.             ParamText(rCodeStr, nil, nil, nil);
  689.             utl_StopAlert(printErrID, nil, 0);
  690.         };
  691.     };
  692. }
  693.  
  694. /*______________________________________________________________________
  695.  
  696.     misc_Periodic - Perform Periodic Tasks.
  697.     
  698.     This routine should be called frequently during disk scans.  It
  699.     keeps the beachball cursor spinning.  Any other periodic actions
  700.     that might be needed should be added here.
  701. _____________________________________________________________________*/
  702.  
  703.  
  704. void misc_Periodic (void)
  705.  
  706. {
  707.     if (BBEnabled) utl_SpinCursor();
  708. }
  709.  
  710.  
  711. /*______________________________________________________________________
  712.  
  713.     misc_DisableBB - Disable Spinning Beachball Cursor.
  714. _____________________________________________________________________*/
  715.  
  716. #pragma segment Main
  717.  
  718. void misc_DisableBB (void)
  719.  
  720. {
  721.     BBEnabled = false;
  722. }
  723.  
  724. #pragma segment misc
  725.  
  726.  
  727. /*______________________________________________________________________
  728.  
  729.     misc_EnableBB - Enable Spinning Beachball Cursor.
  730. _____________________________________________________________________*/
  731.  
  732. void misc_EnableBB (void)
  733.  
  734. {
  735.     BBEnabled = true;
  736. }
  737.  
  738. /*______________________________________________________________________
  739.  
  740.     misc_ListDirectory - List Directory.
  741.     
  742.     
  743.     Entry:        pBlock = pointer to PBGetCatInfo param block.
  744.                     folderList = handle to folder list.
  745.                     refCon = report handle.
  746.                     mfs = true if mfs volume.
  747.                     
  748.     Exit:            function result = true if scan should be canceled.
  749. _____________________________________________________________________*/
  750.  
  751.  
  752. Boolean misc_ListDirectory (CInfoPBRec *pBlock, scn_FListElHandle folderList, 
  753.     long refCon, Boolean mfs)
  754.  
  755. {
  756.     Str255            line;                /* report line */
  757.     char                *p;                /* ptr to current position in report line */
  758.     
  759. #pragma unused (pBlock, refCon, mfs)    
  760.     
  761.     /* Check to see if the report is full. */
  762.     
  763.     if (vscn_CheckFull(Report, 3000)) return true;
  764.     
  765.     /* Put three spaces in the report line for each folder level. */
  766.     
  767.     p = line+1;
  768.     folderList = (**folderList).next;
  769.     while (folderList=(**folderList).next) {
  770.         *p++ = ' ';
  771.         *p++ = ' ';
  772.         *p++ = ' ';
  773.     };
  774.     
  775.     /* Copy file or folder name to report line */
  776.     
  777.     memcpy(p, pBlock->hfileInfo.ioNamePtr+1, *pBlock->hfileInfo.ioNamePtr);
  778.     p += *pBlock->hfileInfo.ioNamePtr;
  779.     
  780.     /* Append (ƒ) for folders. */
  781.     
  782.     if (((pBlock->hfileInfo.ioFlAttrib >> 4) & 1) == 1) {
  783.         *p++ = ' ';
  784.         *p++ = '(';
  785.         *p++ = 'ƒ';
  786.         *p++ = ')';
  787.     };
  788.     
  789.     /* Store report line length. */
  790.     
  791.     *line = p - (line + 1);
  792.     
  793.     /* Write the line to the report. */
  794.     
  795.     rep_Append(Report, line, true, true);
  796.     return false;
  797. }